﻿@model FieldControlViewModel
@{
	if(string.IsNullOrEmpty(Model.FieldValue))
	{
		Model.FieldValue = DataSecurity.MakeFileRndName();
	}
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\" ";
	}
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\"" + Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
}
<div class="layui-input-inline" style="width:75%;">
	<input type="text" class="layui-input layui-disabled" disabled="disabled" name="@Model.Prefix@Model.FieldName" id="@Model.Prefix@Model.FieldName" value="@Model.FieldValue" @Html.Raw(dataVal) />
</div>
<div class="layui-input-inline layui-input-company" style="width:100px;">
	<input type="checkbox" lay-filter="@{@Model.Prefix@Model.FieldName}filter" title="自动编号" lay-skin="primary" checked="checked">
</div>
<span class="layui-bg-green" style="display:inline-block;">@Model.Description</span>
<span style="color:red;" @Html.Raw(dataValMsg)></span>
<script type="text/javascript">
	layui.use(['form'], function () {
		var form = layui.form;

		form.on('checkbox(@{@Model.Prefix@Model.FieldName}filter)', function (data) {
			var TxtNumBuilder = $("#@{@Model.Prefix@Model.FieldName}");
			if (data.elem.checked) {
				TxtNumBuilder.val(GetNewNumber());
				TxtNumBuilder.attr("disabled", true);
				TxtNumBuilder.addClass("layui-disabled");
			}
			else {
				TxtNumBuilder.attr("disabled", false);
				TxtNumBuilder.removeClass("layui-disabled");
			}
		});
	});

</script>